load(
    "//tools/skylark:drake_cc.bzl",
    "drake_cc_googletest",
    "drake_cc_library",
    "drake_cc_package_library",
)
load("//tools/lint:lint.bzl", "add_lint_tests")

package(
    default_visibility = ["//visibility:public"],
)

drake_cc_package_library(
    name = "contact_solvers",
    visibility = ["//visibility:public"],
    deps = [
        ":block_3x3_sparse_matrix",
        ":block_sparse_cholesky_solver",
        ":block_sparse_lower_triangular_or_symmetric_matrix",
        ":block_sparse_matrix",
        ":block_sparse_supernodal_solver",
        ":conex_supernodal_solver",
        ":contact_configuration",
        ":contact_solver",
        ":contact_solver_results",
        ":contact_solver_utils",
        ":linear_operator",
        ":matrix_block",
        ":minimum_degree_ordering",
        ":newton_with_bisection",
        ":pgs_solver",
        ":point_contact_data",
        ":schur_complement",
        ":sparse_linear_operator",
        ":supernodal_solver",
        ":system_dynamics_data",
    ],
)

drake_cc_library(
    name = "block_3x3_sparse_matrix",
    srcs = ["block_3x3_sparse_matrix.cc"],
    hdrs = ["block_3x3_sparse_matrix.h"],
    deps = [
        "//common:default_scalars",
        "//common:essential",
    ],
)

drake_cc_library(
    name = "block_sparse_matrix",
    srcs = ["block_sparse_matrix.cc"],
    hdrs = ["block_sparse_matrix.h"],
    deps = [
        ":matrix_block",
        "//common:default_scalars",
        "//common:essential",
        "//common:unused",
    ],
)

drake_cc_library(
    name = "block_sparse_cholesky_solver",
    srcs = ["block_sparse_cholesky_solver.cc"],
    hdrs = ["block_sparse_cholesky_solver.h"],
    deps = [
        ":block_sparse_lower_triangular_or_symmetric_matrix",
        ":minimum_degree_ordering",
        "//common:copyable_unique_ptr",
        "//common:essential",
        "//common:reset_after_move",
        "//multibody/contact_solvers/sap:partial_permutation",
    ],
)

drake_cc_library(
    name = "contact_configuration",
    srcs = ["contact_configuration.cc"],
    hdrs = ["contact_configuration.h"],
    deps = [
        "//common:essential",
        "//math:geometric_transform",
    ],
)

drake_cc_library(
    name = "contact_solver_results",
    srcs = ["contact_solver_results.cc"],
    hdrs = ["contact_solver_results.h"],
    deps = ["//common:default_scalars"],
)

drake_cc_library(
    name = "multibody_sim_driver",
    testonly = 1,
    srcs = ["test/multibody_sim_driver.cc"],
    hdrs = ["test/multibody_sim_driver.h"],
    deps = [
        "//common:find_resource",
        "//geometry:drake_visualizer",
        "//multibody/parsing",
        "//multibody/plant",
        "//systems/analysis:simulator",
        "//systems/framework:diagram",
        "//systems/framework:diagram_builder",
        "//systems/lcm",
    ],
)

drake_cc_library(
    name = "contact_solver",
    srcs = ["contact_solver.cc"],
    hdrs = ["contact_solver.h"],
    deps = [
        ":contact_solver_results",
        ":contact_solver_utils",
        ":point_contact_data",
        ":system_dynamics_data",
        "//common:default_scalars",
    ],
)

drake_cc_library(
    name = "contact_solver_utils",
    srcs = [],
    hdrs = ["contact_solver_utils.h"],
    deps = [
        "//common:essential",
    ],
)

drake_cc_library(
    name = "linear_operator",
    srcs = ["linear_operator.cc"],
    hdrs = ["linear_operator.h"],
    deps = [
        "//common:default_scalars",
        "//common:essential",
        "//common:nice_type_name",
    ],
)

drake_cc_library(
    name = "matrix_block",
    srcs = ["matrix_block.cc"],
    hdrs = ["matrix_block.h"],
    deps = [
        ":block_3x3_sparse_matrix",
        "//common:default_scalars",
        "//common:essential",
    ],
)

drake_cc_library(
    name = "minimum_degree_ordering",
    srcs = ["minimum_degree_ordering.cc"],
    hdrs = ["minimum_degree_ordering.h"],
    deps = [
        ":block_sparse_lower_triangular_or_symmetric_matrix",
        "//common:essential",
        "//multibody/contact_solvers/sap:partial_permutation",
    ],
)

drake_cc_library(
    name = "newton_with_bisection",
    srcs = ["newton_with_bisection.cc"],
    hdrs = ["newton_with_bisection.h"],
    deps = [
        "//common:essential",
    ],
)

drake_cc_library(
    name = "pgs_solver",
    srcs = [
        "pgs_solver.cc",
    ],
    hdrs = [
        "pgs_solver.h",
    ],
    deps = [
        ":contact_solver",
        ":contact_solver_utils",
        "//common:unused",
    ],
)

drake_cc_library(
    name = "point_contact_data",
    srcs = ["point_contact_data.cc"],
    hdrs = ["point_contact_data.h"],
    deps = [
        ":linear_operator",
        "//common:default_scalars",
    ],
)

drake_cc_library(
    name = "schur_complement",
    srcs = ["schur_complement.cc"],
    hdrs = ["schur_complement.h"],
    deps = [
        ":block_sparse_cholesky_solver",
        ":block_sparse_lower_triangular_or_symmetric_matrix",
        "//common:essential",
    ],
)

drake_cc_library(
    name = "sparse_linear_operator",
    srcs = ["sparse_linear_operator.cc"],
    hdrs = ["sparse_linear_operator.h"],
    deps = [
        ":linear_operator",
        "//common:default_scalars",
        "//common:essential",
    ],
)

drake_cc_library(
    name = "block_sparse_supernodal_solver",
    srcs = ["block_sparse_supernodal_solver.cc"],
    hdrs = ["block_sparse_supernodal_solver.h"],
    deps = [
        ":block_sparse_cholesky_solver",
        ":supernodal_solver",
        "//common:essential",
    ],
)

drake_cc_library(
    name = "conex_supernodal_solver",
    srcs = ["conex_supernodal_solver.cc"],
    hdrs = ["conex_supernodal_solver.h"],
    interface_deps = [
        ":supernodal_solver",
        "//common:essential",
    ],
    deps = [
        "//common:drake_export",
        "@conex_internal//conex:supernodal_solver",
    ],
)

drake_cc_library(
    name = "supernodal_solver",
    srcs = ["supernodal_solver.cc"],
    hdrs = ["supernodal_solver.h"],
    deps = [
        ":block_sparse_matrix",
        ":matrix_block",
        "//common:essential",
    ],
)

drake_cc_library(
    name = "system_dynamics_data",
    srcs = ["system_dynamics_data.cc"],
    hdrs = ["system_dynamics_data.h"],
    deps = [
        ":linear_operator",
        "//common:default_scalars",
    ],
)

drake_cc_library(
    name = "block_sparse_lower_triangular_or_symmetric_matrix",
    srcs = [
        "block_sparse_lower_triangular_or_symmetric_matrix.cc",
    ],
    hdrs = [
        "block_sparse_lower_triangular_or_symmetric_matrix.h",
    ],
    deps = [
        "//common:essential",
    ],
)

drake_cc_googletest(
    name = "block_3x3_sparse_matrix_test",
    deps = [
        ":block_3x3_sparse_matrix",
        "//common/test_utilities:eigen_matrix_compare",
    ],
)

drake_cc_googletest(
    name = "block_sparse_cholesky_solver_test",
    deps = [
        ":block_sparse_cholesky_solver",
        "//common/test_utilities:eigen_matrix_compare",
    ],
)

drake_cc_googletest(
    name = "block_sparse_lower_triangular_or_symmetric_matrix_test",
    deps = [
        ":block_sparse_lower_triangular_or_symmetric_matrix",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
    ],
)

drake_cc_googletest(
    name = "block_sparse_matrix_test",
    deps = [
        ":block_sparse_matrix",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
    ],
)

drake_cc_googletest(
    name = "linear_operator_test",
    deps = [
        ":block_sparse_matrix",
        ":linear_operator",
        "//common/test_utilities:expect_throws_message",
    ],
)

drake_cc_googletest(
    name = "matrix_block_test",
    deps = [
        ":matrix_block",
        "//common/test_utilities:eigen_matrix_compare",
    ],
)

drake_cc_googletest(
    name = "minimum_degree_ordering_test",
    deps = [
        ":minimum_degree_ordering",
    ],
)

drake_cc_googletest(
    name = "newton_with_bisection_test",
    deps = [
        ":newton_with_bisection",
    ],
)

drake_cc_googletest(
    name = "pgs_solver_test",
    deps = [
        ":pgs_solver",
        ":sparse_linear_operator",
        "//common/test_utilities:eigen_matrix_compare",
    ],
)

drake_cc_googletest(
    name = "schur_complement_test",
    deps = [
        ":schur_complement",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
    ],
)

drake_cc_googletest(
    name = "sparse_linear_operator_test",
    deps = [
        ":block_sparse_matrix",
        ":sparse_linear_operator",
        "//common/test_utilities:expect_throws_message",
    ],
)

drake_cc_googletest(
    name = "supernodal_solver_test",
    deps = [
        ":block_sparse_supernodal_solver",
        ":conex_supernodal_solver",
        ":supernodal_solver",
        "//common/test_utilities:expect_throws_message",
    ],
)

drake_cc_googletest(
    name = "system_dynamics_data_test",
    deps = [
        ":sparse_linear_operator",
        ":system_dynamics_data",
    ],
)

add_lint_tests()
